package it.unibo.deis.lia.servicemmhc.clock;


	import java.io.*;
	import java.net.*;

	class ServerClockThread extends Thread
	{
	  private Socket s;
	  int port;
	  private Request richiesta;
	  private Answer risposta;
	  
	  public ServerClockThread(Socket s,int port)
	  { this.s = s;
	  this.port=port;}
	  
	  public void run()
	  {
	    boolean ciclo=true;
	    try
	    {while(ciclo){
	      // ottiene gli stream di I/O dalla socket
	      ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
	     

	      // legge la richiesta
	      richiesta = (Request)ois.readObject();
	      System.err.println(richiesta.time);
	      if(!richiesta.time.equalsIgnoreCase("chiudi")){
	     // s.close();
	     // Socket m=new Socket(InetAddress.getLocalHost(),port);
	      ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
	      risposta = new Answer(System.currentTimeMillis());
	      oos.flush();
	      oos.writeObject(risposta);
	         oos.flush();
	         System.err.println("Risposta inviata!!!"); 
	      }else
	    	  ciclo=false;
	         
	    }
	   
	      // s.close();   //chiudo socket
	    } catch (Exception e) {System.out.println("ERRORE: "+e);}
	  } // run()
	} // class ServerThread


